#include<string>  
#include<vector>  
#include<map>  
#include<algorithm>  
#include <unordered_map> 
#include<iostream> 
  
using namespace std;  
class Solution {  
public:  
    string longestCommonPrefix(vector<string>& strs) {  
        if (strs.empty()) return "";  
        string prefix = strs[0];  
        for (int i = 1; i < strs.size(); i++) {  
            while (strs[i].find(prefix) != 0) {  
                prefix = prefix.substr(0, prefix.length() - 1);  
                if (prefix.empty()) return "";  
            }  
        }  
        return prefix;  
    }  
};
#ifndef COMPILER_ONLINE  
#include"header.cpp"  
#endif  
  
void Test1()  
{  
    //通过定义临时对象，来完成方法的调用  
    vector<string> strs={"flower","flow","flight"};  
    string ret=Solution().longestCommonPrefix(strs);  
    if(ret=="fl")  
    {  
        cout<<"通过了用例1,测试flower,flow,flight通过....OK!"<<endl;  
    }  
    else  
    {  
        cout<<"没有通过用例1,测试flower,flow,flight失败....ERROR!"<<endl;  
    }  
}  
  
void Test2()  
{  
    //通过定义临时对象，来完成方法的调用  
    vector<string> strs={"dog","racecar","car"};  
    string ret=Solution().longestCommonPrefix(strs);  
    if(ret=="")  
    {  
        cout<<"通过了用例2,测试dog,racecar,car通过....OK!"<<endl;  
    }  
    else  
    {  
        cout<<"没有通过用例2,测试dog,racecar,car失败....ERROR!"<<endl;  
    }  
}  
  
void Test3()  
{  
    //通过定义临时对象，来完成方法的调用  
    vector<string> strs={"abc","abcd","abcde"};  
    string ret=Solution().longestCommonPrefix(strs);  
    if(ret=="abc")  
    {  
        cout<<"通过了用例3,测试abc,abcd,abcde通过....OK!"<<endl;  
    }  
    else  
    {  
        cout<<"没有通过用例3,测试abc,abcd,abcde失败....ERROR!"<<endl;  
    }  
}  
  
void Test4()  
{  
    //通过定义临时对象，来完成方法的调用  
    vector<string> strs={"a"};  
    string ret=Solution().longestCommonPrefix(strs);  
    if(ret=="a")  
    {  
        cout<<"通过了用例4,测试a通过....OK!"<<endl;  
    }  
    else  
    {  
        cout<<"没有通过用例4,测试a失败....ERROR!"<<endl;  
    }  
}  

void Test5() {  
    // 通过定义临时对象，来完成方法的调用  
    vector<string> strs = {"abc", "abcd", ""};  
    string ret = Solution().longestCommonPrefix(strs);  
    if (ret == "") {  
        cout << "通过了用例5,测试abc,abcd,''通过....OK!" << endl;  
    } else {  
        cout << "没有通过用例5,测试abc,abcd,''失败....ERROR!" << endl;  
    }  
}  
  
int main() {  
    Test1();  
    Test2();  
    Test3();  
    Test4();  
    Test5();  
    return 0;  
}
